package com.ylz.sjzx.sio.core.group.entity;

import com.alipay.remoting.ConnectionEventType;
import com.alipay.remoting.rpc.RpcClient;
import com.ylz.sjzx.sio.core.group.processor.RpcClientConnectSuccessProcessor;
import com.ylz.sjzx.sio.core.group.processor.RpcClientDisConnectSuccessProcessor;

/**
 * @author
 * @version 1.0
 * @date 2021/3/18
 */
public class RpcClientEntity {
    private RpcClient rpcClient;

    public RpcClientEntity() {
        this.rpcClient = createPpcClient();
    }

    /**
     * rpc客户端
     *
     * @return
     */
    public RpcClient createPpcClient() {
        RpcClient client = new RpcClient();
        //连接成功处理器
        client.addConnectionEventProcessor(ConnectionEventType.CONNECT, new RpcClientConnectSuccessProcessor());
        //连接断开处理器
        client.addConnectionEventProcessor(ConnectionEventType.CLOSE, new RpcClientDisConnectSuccessProcessor());
        client.startup();
        return client;
    }

    public RpcClient getRpcClient() {
        return rpcClient;
    }

    public void setRpcClient(RpcClient rpcClient) {
        this.rpcClient = rpcClient;
    }
}
